import 'package:flutter/material.dart';

import 'package:get/route_manager.dart';

import 'package:kong/widgets/kong_circular_rect_angle.dart';

class BottomAppBarWidget extends StatefulWidget {
  final int current;
  BottomAppBarWidget({
    Key key,
    @required this.current,
  }) : super(key: key);

  @override
  _BottomAppBarWidgetState createState() => _BottomAppBarWidgetState();
}

class _BottomAppBarWidgetState extends State<BottomAppBarWidget> {
  final List<String> aPath = ['/home', '/option', '/discover', '/mine'];

  /* 不会重写继承的getter,请删除`@override` */
  bool get wantKeepAlive => false; // 是否缓存tab页面数据

  @override
  Widget build(BuildContext context) {
    return BottomAppBar(
      elevation: 8,
      notchMargin: 6.0,
      color: Colors.white,
      shape: KongCircularNotchedRectangle(),
      child: Padding(
        padding: EdgeInsets.only(),
        child: MediaQuery.removePadding(
          context: context,
          removeBottom: true,
          child: DefaultTextStyle.merge(
            overflow: TextOverflow.ellipsis,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Expanded(
                  flex: 1,
                  child: Semantics(
                    selected: true,
                    container: true,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        _bottomNavigationTile(
                          icon: Icon(Icons.home),
                          label: Text('ss'),
                          index: 0,
                        ),
                        _bottomNavigationTile(
                          icon: Icon(Icons.home),
                          label: Text('ss'),
                          index: 1,
                        ),
                      ],
                    ),
                  ),
                ),
                SizedBox(
                  width: 56,
                ),
                Expanded(
                  flex: 1,
                  child: Semantics(
                    selected: true,
                    container: true,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        _bottomNavigationTile(
                          icon: Icon(Icons.home),
                          label: Text('ss'),
                          index: 2,
                        ),
                        _bottomNavigationTile(
                          icon: Icon(Icons.home),
                          label: Text('ss'),
                          index: 3,
                        ),
                      ],
                    ),
                  ),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }

  Widget _bottomNavigationTile({
    @required Icon icon,
    @required Widget label,
    @required int index,
  }) {
    return InkResponse(
      onTap: () {
        print('$index - ${widget.current} - ${aPath[index]}');
        if (index == widget.current) return;
        Get.toNamed(aPath[index]);
      },
      // mouseCursor: MaterialStateProperty<MouseCursor>,
      highlightColor: Colors.red,
      child: Padding(
        padding: EdgeInsets.only(top: 15, bottom: 10),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            icon,
            label,
          ],
        ),
      ),
    );
  }
}
